package com.abc.service.impl;

import com.abc.dto.response.FileUploadResponseDto;
import com.abc.service.FileUploadService;
import com.abc.util.MinioUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

/**
 * 文件上传服务实现类
 */
@Slf4j
@Service
public class FileUploadServiceImpl implements FileUploadService {
    
    @Autowired
    private MinioUtil minioUtil;
    
    @Override
    public FileUploadResponseDto uploadFile(MultipartFile file) {
        log.info("开始上传文件: {}", file.getOriginalFilename());
        
        // 使用MinIO工具类上传文件
        String fileName = minioUtil.uploadFile(file);
        
        // 获取文件访问URL
        String fileUrl = minioUtil.getFileUrl(fileName);
        
        log.info("文件上传成功: {}", fileName);
        
        return new FileUploadResponseDto(file.getOriginalFilename(), fileUrl, file.getSize(), file.getContentType());
    }
}
